﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using UI.ParentForm;
using System.Collections;
using Components;
using UI.Lib;
using UI.Lib.Factory;

namespace UI.SellOrder
{
    public partial class FrmOrderQuery : BaseQuery
    {
        public FrmOrderQuery(string modulecode, string action) :
            base(modulecode, action)
        {
            InitializeComponent();

            this.detailDesc = "提示：双击明细行，可以查看订单明细。";
        }

        public override bool BeforePopWin(string name, ref string where, ref string[] others)
        {
            if ("productcode" == name)
            {
                where = string.Format("status ='1' {0}", Context.GetAppKeyWhere("muser", true));
            }
            else if ("sellercode" == name)
            {
                where = string.Format(" status ='1' {0} ", Context.GetAppKeyWhere("usercode", true));
            }
            else if ("shopcode" == name)
            {
                string sellerid = Validation.ToString(this.tbSummary.GetValue("sellerid"));
                if (string.IsNullOrEmpty(sellerid))
                {
                    MessageBox.Show("请先选择销售商！", "提示");
                    this.tbSummary.Focus("sellercode");
                    return false;
                }

                where = string.Format("slistid = '{0}' {1} ", sellerid, Context.GetAppKeyWhere("muser", true));
            }

            return true;
        }

        protected override void DoSearch()
        {
            Hashtable where = new Hashtable();
            where["pid"] = Validation.ToString(this.tbSummary.GetValue("pid")); //控件ID
            where["startdate"] = Validation.ToDate(this.tbSummary.GetValue("startdate"), Global.MinDate); //控件ID
            where["endate"] = Validation.ToDate(this.tbSummary.GetValue("endate"), Global.MaxDate); //结束日期
            where["sellerid"] = Validation.ToString(this.tbSummary.GetValue("sellerid"));
            where["shopid"] = Validation.ToString(this.tbSummary.GetValue("shopid"));
            where["muser"] = Context.Comocde;

            DataTable dt = CommonHelper.Entity.ExecFun("orderquerysourse", where);

            BinderGrid(dt);
        }

        protected override void OnRowDoubleClick(string colName, int rowIndex)
        {
            if (rowIndex < 0) return;

            string listid = Validation.ToString(this.dgvDtl["listid", rowIndex].Value);

            FrmOrderQueryDetail frm = new FrmOrderQueryDetail(this.ModuleCode, this.Action, listid);
            frm.ShowDialog();
        }
    }
}
